package com.qf;

import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

/**
 * 监控整个springboot启动过程的监听器
 */
public class SARListener implements SpringApplicationRunListener {

    public SARListener(SpringApplication springApplication,String[] args){

    }

    @Override
    public void starting(ConfigurableBootstrapContext bootstrapContext) {
        System.out.println("正在启动....");
    }

    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
        System.out.println("环境对象准备完毕....");
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        System.out.println("上下文环境准备完毕....");
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        System.out.println("上下文环境被加载....");
    }


    /**
     * 整个springboot核心流程执行完毕后，要执行操作，放在这个方法中
     * @param context
     */
    @Override
    public void running(ConfigurableApplicationContext context) {
        System.out.println("spirngboot流程执行完毕");
    }
}
